package com.bupt.ilink.mapper;

import com.bupt.ilink.entity.DatasetMetadata;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author zhangbo
 * @description 针对表【dataset_metadata】的数据库操作Mapper
 * @createDate 2024-07-25 10:53:08
 * @Entity generator.domain.DatasetMetadata
 */
@Mapper
public interface DatasetMetadataMapper extends BaseMapper<DatasetMetadata> {
    // 其他方法...

    /**
     * 查询所有数据集的名称
     * csv批量导入数据
     * @return 包含所有名称的列表
     */
    List<String> getAllNames();

    //  用于查询  数据集详情文件
    @Select("SELECT * FROM dataset_metadata WHERE dataset_id = #{datasetId}")
    DatasetMetadata selectById(String datasetId);

    //  用于通过关键词查找数据集
    @Select("SELECT * FROM dataset_metadata WHERE name LIKE CONCAT('%', #{keywords}, '%')")
    List<DatasetMetadata> selectByKeywords(String keywords);

    @Select("<script>" +
            "SELECT * FROM dataset_metadata WHERE dataset_id IN " +
            "<foreach item='item' index='index' collection='datasetIds' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<DatasetMetadata> selectByDatasetIds(@Param("datasetIds") List<Long> datasetIds);

    @Update("UPDATE dataset_metadata SET download_num = download_num + 1 WHERE dataset_id = #{datasetId}")
    void incrementDownloadNum(@Param("datasetId") Long datasetId);

    @Update("UPDATE dataset_metadata SET share_num = share_num + 1 WHERE dataset_id = #{datasetId}")
    void incrementShareNum(@Param("datasetId") Long datasetId);

    @Update("UPDATE dataset_metadata SET click_num = click_num + 1 WHERE dataset_id = #{datasetId}")
    void incrementClickNum(@Param("datasetId") Long datasetId);

    @Update("UPDATE dataset_metadata SET favorite_num = favorite_num + 1 WHERE dataset_id = #{datasetId}")
    void incrementFavoriteNum(@Param("datasetId") Long datasetId);
}



